<?php
/**
 * Access Control
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo
 */
class Access_AppController extends Zend_Controller_Action
{

    public function init()
    {
        $this->view->headLink()->appendStylesheet($this->view->baseUrl("/css/access/app_access.css"));
        $this->view->headScript()->appendFile($this->view->baseUrl('/js/access/rolelist.js'));

        $roleId = $this->_request->getParam("roleid");
        $roles = new Access_Model_Roles();
        $roleList = $roles->getList();

        if(empty($roleId)) {

            $firstRole = array();
            $firstRole = pos($roleList);
            $roleId = $firstRole["id"];
        }
        $this->view->roleId = $roleId;
        $this->view->roleList = array('roleList' => $roleList, 'roleId' => $roleId);
    }
    /**
     * Show access for roles
     *
     * @return void
     */
    public function indexAction()
    {
        $module = new Access_Model_Module;
        $moduleList = $module->getAccessList($this->view->roleId);

        $this->view->moduleList = $moduleList;
        //num2text
        $this->view->numAsWord = array("Null", "One", "Two", "Three", "Four", "Five");
    }
    
    /**
     * Edit Roles
     * 
     * @return void
     */
    public function editAction()
    { 

        if($this->_request->getPost("save")) {
            
            $formRequest = $this->_request->getPost("form");
            $user = new Access_Model_User;
            $user->deleteRules($this->view->roleId);
            if ($formRequest) {
                $user->insertRules($this->view->roleId, $formRequest);
            }
            $this->_forward('index', null, null, array('roleid' => $this->view->roleId));
        }
        $module = new Access_Model_Module;
        $moduleList = $module->getAccessList($this->view->roleId);

        $this->view->moduleList = $moduleList;
        //num2text
        $this->view->numAsWord = array("Null", "One", "Two", "Three", "Four", "Five");
    }
}